#pragma once
#ifndef SYPX_FONT
#define SYPX_FONT

#include "Sprite.h"

struct FT_FaceRec_;
typedef struct FT_FaceRec_*  FT_Face;

namespace SypX
{
	/*!
	[Non-managed Resource]
	Though Fonts derive from the Resource class, they are not intended to be managed by the ResourceManager
	and will therefore maintain a dummy MeshInstance to prevent it's reference count from reaching 0.
	The reason for this design is that we do not want any instance object to reference the Font in order
	to simplify text rendering. Moreover, the only information required to draw text is the positional data and
	text which does not warrant the usage of a seperate instance object
	Fonts can only be created via Engine::loadFontFromFile() and deleted only via Engine::removeFont()
	Attempting to new/delete a Font object will result in undefined behaviour.
	*/
	class SYPXAPI Font : public Sprite
	{
	public:
		Font(void);
		~Font(void);
		///Draws test at x,y on screen. All drawText calls are buffered into a data array and are not drawn to screen
		///until drawBufferedInstances() is called.
		///TODO: Currently each color component is a float which is 4 bytes each, meaning 16 bytes for RGBA
		///Optimise it to use a UByte per component and reduce it to 4 bytes by using a seperate UByte buffer
		void drawText(const String& text, float x, float y, float z = 0);
		///Returns the total width the text string will require when rendered
		float calcTextWidth(const String& text);
		///Processes text and adds \n at appropriate points to ensure text will fit within width.
		///Note: This is a costly operation and should only be done once when text changes.
		String wordWrap(const String& text, float width);
		///Returns the number of characters that can fit in 1 line.		
		UInt numOfChars(const String& text,float width);
		///Returns the maximal height of a character for this particular font in pixels
		float getFontSizeY();
	protected:		
		float fontSizeX;	//Pixel width of each character in texture
		float fontSizeY;	//Pixel height of each character in texture		
		UShortArray fontWidths;
		FT_Face     face;      /* handle to freetype2 face object */
		friend class Engine;	//Engine loads the fonts
	};
}
#endif